// upload.controller.ts
import {
  Controller,
  Body,
  Post,
  UploadedFile,
  UseInterceptors,
} from '@nestjs/common';
import { FileInterceptor } from '@nestjs/platform-express';
import { UploadService } from './upload.service';
import { Public } from 'src/common/decorators/public.decorator';
@Controller('upload')
export class UploadController {
  constructor(private readonly uploadService: UploadService) {}
  @Post('avatar')
  @Public()
  @UseInterceptors(FileInterceptor('file'))
  upload(@UploadedFile() file: any) {
    console.log('upload', file); // return this.uploadService.upload();
    return this.uploadService.uploadAvatar(file);
  }

  // 上传文件 并把文件存储在./public/files目录下
  @Post('file')
  @Public()
  @UseInterceptors(FileInterceptor('file'))
  uploadFile(@UploadedFile() file: any) {
    return this.uploadService.changeExcel(file);
  }

  // 上传word
  @Post('word')
  @Public()
  @UseInterceptors(FileInterceptor('file'))
  uploadWord(@UploadedFile() file: any) {
    return this.uploadService.excuteWord(file);
  }

  // 对比两个word差异
  @Post('wordDiff')
  @Public()
  wordDiff(@Body() body: any) {
    return this.uploadService.wordDiff(body.url1, body.url2);
  }
}
